console.log("do dusku");

function getQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return r[2];
    };
    return 0;
}

$(document).ready(function() {





    setTimeout(() => {
        $(".jsx-2601963492.button").click();
    }, 1000);

    setTimeout(() => {

        var sku_map = [];

        $("body").find(".rectangle").each(function(e){
            let sku_item = {};
            sku_item['pic'] = $(this).find('img').attr("src");
            sku_item['name'] = $(this).attr("title").trim();
            sku_map.push(sku_item)
        });


        var sku_size = [];
        $(".jsx-706577070.square").each(function(e){
            let sku_item = {};
            sku_item['pic'] = $(this).find('img').attr("src");
            sku_item['name'] = $(this).attr("title").trim();
            sku_size.push(sku_item)
        });

        var small_pic = [];
        $(".image-small").each(function(e){
            small_pic.push($(this).find('img').attr("src"));
        });

        var spuId = getQueryString("spuId");
        var attrs = {};

        $(".jsx-1209583269.wrapper").find("div").each(function(e){
            let attr_key = $(this).find("span").eq(0).text().trim();
            let attr_value =  $(this).find("span").eq(1).text().trim();
            attrs[attr_key] = attr_value;
        });

        var data = {};
        data.small_pic = small_pic;
        data.attrs = attrs;
        data.spu_id = spuId;
        data.sku_map = sku_map;
        data.sku_size = sku_size;
        var type = "du_sku_info";
        chrome.runtime.sendMessage({ data: {type,data }, close: false })
        console.log(data);

    }, 2000);




})